*------------------*
* Data Preparation *
*------------------*
use "wave 7.dta", replace
keep if B_COUNTRY==446 // keep Macau module

*********************************
* Housekeeping for day variable *
*********************************
sort J_INTDATE
tab J_INTDATE

todate J_INTDATE, gen(date_int)  p(yyyymmdd)
gen day = date_int - td(24Nov2019)
tab day

* treatment and control group
gen tr = 1 if date_int>td(24Nov2019)
replace tr= 0 if date_int<td(24Nov2019) 

label define lbtr  0"Control" 1"Treatment" 
label values tr lbtr

* dummy: sieges sample (coded as 0) and post electoral-shock sample (coded as 1)
gen shock=. 
replace shock=0 if day>=-13 & day<=-1
replace shock=1 if day>=1 & day<=14

***************************
* Clean missing responses *
***************************
foreach x of varlist Q1-Q290{
	tab `x', m
	replace `x'=. if `x'==-1 | `x'==-2 | `x'==-3 |  `x'==-4 | `x'==-5
	tab `x', m
}

***************************
* Importance of democracy *
***************************
norm Q250, method(mmx)
rename mmx_Q250 demo_imp


**********************
* Electoral Fairness *
**********************
* factor analysis of electoral process
recode Q224 Q229 Q232 (4=1) (3=2) (2=3) (1=4) // Response is revere-coded such that larger values denote a higher perception of electoral fairness
rename Q224 votecount // Votes are counted fairly
rename Q229 officials // Election officials are fair
rename Q232 genuine // Voters are offered a genuine choice in the elections


factor votecount officials genuine 
alpha votecount officials genuine // * Cronbach's alpha
pca votecount officials genuine // principal component analysis
predict fc_fair 
norm fc_fair, method(mmx)
rename mmx_fc_fair fair  // 0 = unfair ; 1 = fair
sum fair


***************
* Vote choice *
***************
* vote choice for establishment (excluding missing)
gen ccp_2=.
replace ccp_2=1 if Q223==446001 | Q223==446006 | Q223==446007 | Q223==446009 | Q223==446010 | Q223==446012 | Q223==446014 | Q223==446018 | Q223==446016 | Q223==446003
replace ccp_2=0 if Q223!=446001 & Q223!=446006 & Q223!=446007 & Q223!=446009 & Q223!=446010 & Q223!=446012 & Q223!=446014 & Q223!=446018 & Q223!=446016 & Q223!=446003
replace ccp=. if Q223==.
tab  Q223 ccp_2, nol m

* vote choice for establishment (including missing)
gen ccp=.
replace ccp=1 if Q223==446001 | Q223==446006 | Q223==446007 | Q223==446009 | Q223==446010 | Q223==446012 | Q223==446014 | Q223==446018 | Q223==446016 | Q223==446003
replace ccp=0 if Q223!=446001 & Q223!=446006 & Q223!=446007 & Q223!=446009 & Q223!=446010 & Q223!=446012 & Q223!=446014 & Q223!=446018 & Q223!=446016 & Q223!=446003
replace ccp=0 if Q223==.
tab  Q223 ccp, nol m


******************************************
* Other types of political participation *
****************************************
fre Q209 Q210 Q211 Q212
recode Q209 Q210 Q211 Q212 (1=3) (3=1)
gen petition=Q209 // Signing a petition 
gen boycott=Q210  // Joining in boycotts
gen demonstration=Q211 // Attending lawful/peaceful demonstrations
gen strike=Q212 // Joining unofficial strikes
label define lbaction  1"Would never do" 2"Might do" 3"Have done"
label values petition boycott demonstration strike lbaction
fre petition boycott demonstration strike


fre Q213 Q214 Q215
recode Q213 Q214 Q215 (1=3) (3=1)
gen donate=Q213 // Donating to a group or campaign
gen encourage_action=Q214 // Encouraging others to take action about political issues
gen encourage_vote=Q215 // Encouraging others to vote
label values donate encourage_action encourage_vote lbaction
fre donate encourage_action encourage_vote


*****************************
* Online information search *
*****************************
clonevar search=Q217
recode search (1=3) (3=1)

label define lbsearch  1"Would never do" 2"Might do" 3"Have done" 
label values search lbsearch

**************
* Covariates * 
**************
foreach x of varlist Q260 Q262 Q275R Q284 Q287 Q288 Q289 {
	tab `x', m
}

rename Q260 gender
rename Q262 age
rename Q275R edu
rename Q287 sub_class
rename Q284 sector
recode sector (3 2 = 0)
tab sector
label define lbsector  0"Private sector"  1"Public sector" 
label values sector lbsector

rename Q288 inc
rename Q281 work

rename Q263 imm
label define lbimm 1"Native" 2"Immigrant"
label values imm lbimm

rename Q273 marital
recode marital (2=1) (3=2) (4=3) (5=4) (6=5)
label define lbmarital  1"Marital status: Married" 2"Marital status: Divorced" 3"Marital status: Separated" 4"Marital status: Widowed" 5"Marital status: Single"
label values marital lbmarital
tab marital, m


* recode edu into binary
recode edu (3=1) (2=0) (1=0)
label define lbedu  0"Without higher education" 1"With higher education" 
label values edu lbedu

* recode religion 
rename Q289 religion
replace religion=. if religion==-5
replace religion=1 if religion>1
label define lbreli  0"Does not belong to a religion" 1"Belong to a religion" 
label values religion lbreli


****************
* Middle class *
****************
* Main analysis: (1) have tertiary education & (2) household income is equal to or above the 5th decile
gen mid_inc=. 
replace mid_inc=1 if inc>=5 & edu==1
replace mid_inc=0 if inc<5 | edu!=1
replace mid_inc=. if inc==. 
replace mid_inc=. if edu==. 


* Alternative specification: (1) have tertiary education, (2) household income is equal to or above the 5th decile, and (3) in middle-class professions
fre work
gen mid_occ=.
replace mid_occ=0 if (work==4 | work==5 | work==7 | work==8 | work==9 | work==10 | work==11 | work==0) 
replace mid_occ=0 if edu!=1
replace mid_occ=0 if inc<5
replace mid_occ=1 if (work==1 | work==2 | work==3 | work==6) & edu==1 & inc>=5 //1.- Professional and technical; 2.- Higher administrative; 3.- Clerical; 6.- Skilled worker
replace mid_occ=. if work==.
replace mid_occ=. if edu==.
replace mid_occ=. if inc==.
fre mid_occ


label define lbmid 0 "Non-middle class" 1 "Middle class"
label values mid_inc mid_occ lbmid


*********************
* Entropy weighting *
*********************
ebalance tr mid_inc##c.age mid_inc##gender mid_inc##i.imm mid_inc##i.marital mid_inc##i.edu mid_inc##c.inc, tar(1)
rename  _webal weight_mid_inc


************************
* Dataset for analysis *
************************
fre inc
drop if inc>8 // drop wealthy class
drop if day==0 // drop day 0

* Summary statistics
asdoc sum demo_imp fair ccp petition boycott demonstration strike donate encourage_action encourage_vote sector search edu inc age gender  imm marital reli, replace tzok dec(2) save(sum stat.rtf)

save "macau.dta", replace 


*-------------------------*
* Covariate balance tests *
*-------------------------*
use "macau.dta", replace 

eststo edu: reg tr i.edu  // treated group is more likely to have higher education
sum edu
display .0876131/.4917537

eststo inc: reg tr inc
sum inc
display .0277787/1.463406

eststo age: reg tr age // treated group is slightly younger
sum age 
display .0022929/16.72077

eststo gender: reg tr 1.gender

eststo imm: reg tr i.imm // immigrant is less likely to be in the treated group
sum imm 
display .066699/.4935897


forvalues i=1/5{
	eststo marital`i': reg tr `i'.marital  // married people is less likely to be in the treated group
}
gen single=.
replace single=1 if marital==5
replace single=0 if marital>=1 & marital<=4
sum single
display .0786963/.4885678

eststo reli: reg tr i.reli


coefplot edu inc age gender imm marital1 marital2 marital3 marital4 marital5 reli  , ///
	drop(_cons) xtitle("Estimate") xline(0, lpattern(l)) legend(off) mcolor(black)  ciopts(lcolor(black)) offset(0) ///
	mlabel format(%9.2g) mlabposition(11) mlabgap(*2)
graph export "cov_balance.png", as(png) replace 

*---------------*
* Main analysis *
*---------------*
set scheme white_ptol
* define control variables
global controls "c.age##c.age i.gender i.imm i.marital i.reli"

*********************************
* DV 1: importance of democracy *
*********************************
eststo demo_inc: reg demo_imp i.tr##i.mid_inc $controls 
quietly estadd local bw "Full sample": demo_inc
quietly estadd local fe "Yes": demo_inc
quietly estadd local ctrl "Yes": demo_inc
lincom 1.tr + 1.tr#1.mid_inc
margins tr, by(mid_inc)
mplotoffset, title("Importance of Democracy", size(medium) box bexpand) ylabel(0.5(0.1)0.9) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		plot2opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci2opts(color("102 197 151")) ///
		legend(position(6) row(1)) saving(demo_inc, replace)
		
****************************
* DV 2: electoral fairness *
****************************
eststo fair_inc: reg fair i.tr##i.mid_inc  $controls 
quietly estadd local bw "Full sample": fair_inc
quietly estadd local fe "Yes": fair_inc
quietly estadd local ctrl "Yes": fair_inc
lincom 1.tr + 1.tr#1.mid_inc
margins tr, by(mid_inc)
mplotoffset, title("Electoral fairness", size(medium) box bexpand) ylabel(0.5(0.1)0.9) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		plot2opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci2opts(color("102 197 151")) ///
		legend(position(6) row(1)) saving(fair_inc, replace)

***********************************
* DV 3: support for pro-CCP party *
***********************************
eststo ccp_inc: reg ccp i.tr##i.mid_inc $controls 
quietly estadd local bw "Full sample": ccp_inc
quietly estadd local fe "Yes": ccp_inc
quietly estadd local ctrl "Yes": ccp_inc
lincom 1.tr + 1.tr#1.mid_inc
lincom 1.mid_inc + 1.tr#1.mid_inc
margins tr, by(mid_inc)
mplotoffset, title("Pro-CCP parties", size(medium) box bexpand) ylabel(0(0.1)0.5) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		plot2opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci2opts(color("102 197 151")) ///
		legend(position(6) row(1)) saving(ccp_inc, replace)		

		
* Figure 2 & Table 2
grc1leg demo_inc.gph fair_inc.gph ccp_inc.gph, r(1) saving(full_inc, replace) 
graph export "main.png", as(png) replace

esttab  demo_inc fair_inc ccp_inc using "main.rtf", b(2) se(2) replace ///
	scalars("ctrl Controls" "N Observations" "r2 R-squared") ///
	label wide note onecell nobaselevels  noomitted nonumbers  lines varwidth(15) ///
	keep (1.tr 1.mid_inc 1.tr#1.mid_inc _cons) ///
	coeflabel(1.tr "Tr" 1.tr#1.mid_inc "Tr x Middle class") ///
	mtitles("(1) Importance of democracy" "(2) Electoral fairness" "(3) Pro-CCP parties" ) modelwidth(7) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
	note("Note: Entries are coefficients of OLS regression. Standard errors are shown in parentheses. All models include demographic controls (age, square term of age, gender, income, immigration status, marital status, and religion).") ///
	title("Table 2. Regression Estimates: Spillover effects of the 2019 DC electoral shock") 



******************************************
* Other types of political participation *
******************************************
eststo petition: reg petition i.tr##i.mid_inc $controls 	
quietly estadd local bw "Full sample": petition
quietly estadd local fe "Yes": petition
quietly estadd local ctrl "Yes": petition
lincom 1.tr + 1.tr#1.mid_inc

eststo boycott: reg boycott i.tr##i.mid_inc $controls 	
quietly estadd local bw "Full sample": boycott
quietly estadd local fe "Yes": boycott
quietly estadd local ctrl "Yes": boycott
lincom 1.tr + 1.tr#1.mid_inc

eststo demonstration: reg demonstration i.tr##i.mid_inc $controls 	
quietly estadd local bw "Full sample": demonstration
quietly estadd local fe "Yes": demonstration
quietly estadd local ctrl "Yes": demonstration
lincom 1.tr + 1.tr#1.mid_inc

eststo strike: reg strike i.tr##i.mid_inc $controls 	
quietly estadd local bw "Full sample": strike
quietly estadd local fe "Yes": strike
quietly estadd local ctrl "Yes": strike
lincom 1.tr + 1.tr#1.mid_inc

eststo donate: reg donate i.tr##i.mid_inc $controls 	
quietly estadd local bw "Full sample": donate
quietly estadd local fe "Yes": donate
quietly estadd local ctrl "Yes": donate
lincom 1.tr + 1.tr#1.mid_inc

eststo encourage_action: reg encourage_action i.tr##i.mid_inc $controls 	
quietly estadd local bw "Full sample": encourage_action
quietly estadd local fe "Yes": encourage_action
quietly estadd local ctrl "Yes": encourage_action
lincom 1.tr + 1.tr#1.mid_inc

eststo encourage_vote : reg encourage_vote  i.tr##i.mid_inc $controls 	
quietly estadd local bw "Full sample": encourage_vote 
quietly estadd local fe "Yes": encourage_vote 
quietly estadd local ctrl "Yes": encourage_vote 
lincom 1.tr + 1.tr#1.mid_inc

* Table B.1
esttab petition boycott demonstration strike donate encourage_action encourage_vote using "pol_part.rtf", b(2) se(2) replace ///
	scalars("ctrl Controls" "N Observations" "r2 R-squared") ///
	label wide note onecell nobaselevels  noomitted nonumbers  lines varwidth(11) ///
	keep (1.tr 1.mid_inc 1.tr#1.mid_inc _cons) ///
	coeflabel(1.tr "Tr" 1.tr#1.mid_inc "Tr x Middle class") ///
	mtitles("(1) Sign a petition" "(2) Join in boycotts" "(3) Attend lawful/peaceful demonstrations" "(4) Join unofficial strikes" ///
	"(5) Donate to a group/campaign" "(6) Encourage others to take action about political issues" "(7) Encourage others to vote") modelwidth(8) ///
	star(* 0.05 ** 0.01 *** 0.001)  ///
	note("Note: Entries are coefficients of OLS regression. Standard errors are shown in parentheses. All models include demographic controls (age, square term of age, gender, income, immigration status, marital status, and religion).") ///
	title("Table B.1. Other self-reported political behavior") 	

	
* ---------------------------------------------------------*
* Comparing sieges sample with post electoral-shock sample *
* ---------------------------------------------------------*
* Importance of democracy
eststo demo_inc0: reg demo_imp i.shock $controls if mid_inc==0 
quietly estadd local bw "Lower class": demo_inc0
quietly estadd local ctrl "Yes": demo_inc0
margins shock
mplotoffset, title("Importance of Democracy (Lower class)", size(medium) box bexpand) ylabel(0.5(0.1)0.9) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		xlab(-.5 " " 0 `""Sieges Sample" "(Day -14 to -1)""' 1 `""Post-electoral shock sample" "(Day 1 to 14)""' 1.5 " " ) ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		legend(position(6) row(1)) saving(demo_mid_inc0, replace)
		
eststo demo_inc1: reg demo_imp i.shock $controls if mid_inc==1 
quietly estadd local bw "Middle class": demo_inc1
quietly estadd local ctrl "Yes": demo_inc1
margins shock
mplotoffset, title("Importance of Democracy (Middle class)", size(medium) box bexpand) ylabel(0.5(0.1)0.9) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		xlab(-.5 " " 0 `""Sieges Sample" "(Day -14 to -1)""' 1 `""Post-electoral shock sample" "(Day 1 to 14)""' 1.5 " " ) ///
		plot1opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci1opts(color("102 197 151")) ///	
		legend(position(6) row(1)) saving(demo_mid_inc1, replace) 

* Electoral fairness
eststo fair_inc0: reg fair i.shock $controls if mid_inc==0 
quietly estadd local bw "Lower class": fair_inc0
quietly estadd local ctrl "Yes": fair_inc0
margins shock
mplotoffset, title("Electoral fairness (Lower class)", size(medium) box bexpand) ylabel(0.5(0.1)0.8) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		xlab(-.5 " " 0 `""Sieges Sample" "(Day -14 to -1)""' 1 `""Post-electoral shock sample" "(Day 1 to 14)""' 1.5 " " ) ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		legend(position(6) row(1)) saving(fair_mid_inc0, replace) 

eststo fair_inc1: reg fair i.shock $controls if mid_inc==1 
quietly estadd local bw "Middle class": fair_inc1
quietly estadd local ctrl "Yes": fair_inc1
margins shock
mplotoffset, title("Electoral fairness (Middle class)", size(medium) box bexpand) ylabel(0.5(0.1)0.8) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		xlab(-.5 " " 0 `""Sieges Sample" "(Day -14 to -1)""' 1 `""Post-electoral shock sample" "(Day 1 to 14)""' 1.5 " " ) ///
		plot1opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci1opts(color("102 197 151")) ///	
		legend(position(6) row(1)) saving(fair_mid_inc1, replace) 

	
* Figure 3 & Table B.2
graph combine demo_mid_inc1.gph demo_mid_inc0.gph fair_mid_inc1.gph fair_mid_inc0.gph, r(2)	
graph export "bw.png", as(png) replace		


esttab  demo_inc1 demo_inc0 fair_inc1 fair_inc0  using "bw.rtf", b(2) se(2) replace ///
	scalars("ctrl Controls" "bw Sample" "N Observations" "r2 R-squared") ///
	label wide note onecell nobaselevels  noomitted nonumbers  lines varwidth(15) ///
	keep (1.shock _cons) ///
	coeflabel(1.shock "Post-Electoral Shock Sample (Day 1 to 14)") ///
	mtitles("(1) Importance of democracy" "(2) Importance of democracy" "(3) Electoral fairness" "(4) Electoral fairness" ) modelwidth(10) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
	note("Note: Entries are coefficients of OLS regression. The reference category is the sieges sample (Day -14 to -1). Standard errors are shown in parentheses. All models include demographic controls (age, square term of age, gender, income, immigration status, marital status, and religion). ") ///
	title("Table B.2. Bandwidth Restriction: Comparing the Sieges Sample with the Post-electoral Shock Sample.") 


* ------------------*
* Robustness checks *
* ------------------*
*********************************************
* Alternative specification of middle class *
*********************************************
eststo demo_occ: reg demo_imp i.tr##i.mid_occ $controls 
quietly estadd local bw "Full sample": demo_occ
quietly estadd local fe "Yes": demo_occ
quietly estadd local ctrl "Yes": demo_occ
lincom 1.tr + 1.tr#1.mid_occ
margins tr, by(mid_occ)
mplotoffset, title("Importance of Democracy", size(medium) box bexpand) ylabel(0.5(0.1)0.9) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		plot2opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci2opts(color("102 197 151")) ///
		legend(position(6) row(1)) saving(demo_occ, replace)

eststo fair_occ: reg fair i.tr##i.mid_occ $controls 
quietly estadd local bw "Full sample": fair_occ
quietly estadd local fe "Yes": fair_occ
quietly estadd local ctrl "Yes": fair_occ
lincom 1.tr + 1.tr#1.mid_occ
margins tr, by(mid_occ)
mplotoffset, title("Electoral fairness", size(medium) box bexpand) ylabel(0.5(0.1)0.9) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		plot2opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci2opts(color("102 197 151")) ///
		legend(position(6) row(1)) saving(fair_occ, replace)

eststo ccp_occ: reg ccp i.tr##i.mid_occ $controls 
quietly estadd local bw "Full sample": ccp_occ
quietly estadd local fe "Yes": ccp_occ
quietly estadd local ctrl "Yes": ccp_occ
lincom 1.tr + 1.tr#1.mid_occ
margins tr, by(mid_occ)
mplotoffset, title("Pro-CCP parties", size(medium) box bexpand) ylabel(0(0.1)0.5) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		plot1opts(msymbol(O) mcolor("239 131 125") lpattern(".") lcolor("239 131 125")) ci1opts(color("239 131 125"))  ///
		plot2opts(msymbol(O) mcolor("102 197 151") lpattern(solid) lcolor("102 197 151")) ci2opts(color("102 197 151")) ///
		legend(position(6) row(1)) saving(ccp_occ, replace)		

		
* Figure B.4 & Table B.3
grc1leg demo_occ.gph fair_occ.gph ccp_occ.gph, r(1) saving(full_occ, replace) 
graph export "mid_occ.png", as(png) replace


esttab  demo_occ fair_occ ccp_occ using "mid_occ.rtf", b(2) se(2) replace ///
	scalars("ctrl Controls" "N Observations" "r2 R-squared") ///
	label wide note onecell nobaselevels  noomitted nonumbers  lines varwidth(15) ///
	keep (1.tr 1.mid_occ 1.tr#1.mid_occ _cons) ///
	coeflabel(1.tr "Tr" 1.tr#1.mid_occ "Tr x Middle class") ///
	mtitles("(1) Importance of democracy" "(2) Electoral fairness" "(3) Pro-CCP parties") modelwidth(7) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
	note("Note: Entries are coefficients of OLS regression. Standard errors are shown in parentheses. Respondents are coded as middle class if they have higher education, and their household income is equal to or above the 5th step. In addition, they have to work in one of the middle-class occupations: (i) professional and technical (ii) higher administrative, (iii) clerical (e.g. office manager, civil servant), and (iv) skilled worker. All models include demographic controls (age, square term of age, gender, income, immigration status, marital status, and religion).") ///
	title("Table B.3. Replication of Table 2: Operationalization of middle class that includes occupations") 	

*******************	
* Entropy balance *
*******************
eststo demo_inc_eb: reg demo_imp i.tr##i.mid_inc  [pweight= weight_mid_inc]
lincom 1.tr + 1.tr#1.mid_inc

eststo fair_inc_eb: reg fair i.tr##i.mid_inc [pweight= weight_mid_inc]
lincom 1.tr + 1.tr#1.mid_inc

eststo ccp_inc_eb: reg ccp i.tr##i.mid_inc [pweight= weight_mid_inc]
lincom 1.tr + 1.tr#1.mid_inc

* Table B.4
esttab  demo_inc_eb fair_inc_eb ccp_inc_eb using "ebalance.rtf", b(2) se(2) replace ///
	scalars("N Observations" "r2 R-squared") ///
	label wide note onecell nobaselevels  noomitted nonumbers  lines varwidth(15) ///
	keep (1.tr 1.mid_inc 1.tr#1.mid_inc _cons) ///
	coeflabel(1.tr "Tr" 1.tr_pseudo_1#1.mid_inc "Tr x Middle class") ///
	mtitles("(1) Importance of democracy" "(2) Electoral fairness" "(3) Pro-CCP parties" "(4) Importance of democracy" "(5) Electoral fairness" "(6) Pro-CCP parties") modelwidth(7) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
	note("Note: Entries are coefficients of OLS regression. Standard errors are shown in parentheses. Entropy weight is created based on observable covariates, including education, income, age, gender, income, immigration status, marital status, and religion. Covariates are balanced within each social class. The moment is set to the means of each covariate.") ///
	title("Table B.4. Replication of Table 2 with entropy balancing") 

	
	
********************	
* Ologit and Logit *
********************		
eststo demo_imp_ologit: ologit demo_imp i.tr##i.mid_inc $controls
quietly estadd local fe "Yes": demo_imp_ologit
quietly estadd local ctrl "Yes": demo_imp_ologit
lincom 1.tr + 1.tr#1.mid_inc

eststo ccp_logit: logit ccp i.tr##i.mid_inc $controls 
quietly estadd local fe "Yes": ccp_logit
quietly estadd local ctrl "Yes": ccp_logit
lincom 1.tr + 1.tr#1.mid_inc


* Table B.5
esttab  demo_imp_ologit ccp_logit using "glm.rtf", b(2) se(2) replace ///
	scalars("ctrl Controls" "N Observations" "r2_p pseudo R-squared") ///
	label wide note onecell nobaselevels  noomitted nonumbers  lines varwidth(15) ///
	keep (1.tr 1.mid_inc 1.tr#1.mid_inc) ///
	coeflabel(1.tr "Tr" 1.tr#1.mid_inc "Tr x Middle class") ///
	mtitles("(1) Importance of democracy" "(2) Pro-CCP parties") modelwidth(7) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
	note("Note: Entries are coefficients of generalized linear regression (Model 1 uses ordered logit regression; Model 2 uses logit regression). Standard errors are shown in parentheses. All models include demographic controls (age, square term of age, gender, income, immigration status, marital status, and religion)") ///
	title("Table B.5. Generalized Linear Regression Estimates") 


*************************
* Non-response analysis * 
*************************
* Missing dummies for 3 DVs
gen m_demo_imp=.
replace m_demo_imp=1 if demo_imp==.
replace m_demo_imp=0 if demo_imp!=.
tab demo_imp m_demo_imp, m

gen m_fair=.
replace m_fair=1 if fair==.
replace m_fair=0 if fair!=.
tab fair m_fair, m

gen m_ccp=.
replace m_ccp=0 if Q223!=. 
replace m_ccp=1 if Q223==. 
tab Q223 m_ccp, m

fre m_demo_imp m_fair m_ccp

* Table B.6 (t-tests for missing outcomes (full sample))
ttest m_demo_imp if mid_inc==0, by(tr)
ttest m_demo_imp if mid_inc==1, by(tr)

ttest m_fair if mid_inc==0, by(tr)
ttest m_fair if mid_inc==1, by(tr)

ttest m_ccp if mid_inc==0, by(tr)
ttest m_ccp if mid_inc==1, by(tr)

	
* ----------*
* Mechanism *
* ----------*
********************		
* State dependence *
********************
reg demo_imp i.tr##i.mid_inc##i.sector $controls 
eststo sector_demo: margins, dydx(sector) by(mid_inc tr) post

reg fair i.tr##i.mid_inc##i.sector $controls 
eststo sector_fair: margins, dydx(sector) by(mid_inc tr) post

* Table C.1
esttab sector_demo sector_fair using "sector.rtf", b(2) se(2) replace ///
	label wide note onecell nobaselevels  noomitted nonumbers  lines varwidth(30) ///
	keep (0.mid_inc#0.tr 0.mid_inc#1.tr 1.mid_inc#0.tr 1.mid_inc#1.tr) ///
	coeflabel(0.mid_inc#0.tr "Lower-class control group" 0.mid_inc#1.tr "Lower-class treatment group" ///
	1.mid_inc#0.tr "Middle-class control group"  1.mid_inc#1.tr "Middle-class treatment group") ///
	mtitles("(1) Importance of democracy" "(2) Electoral fairness" "(3) Vote preference") modelwidth(7) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001)  ///
	note("Note: Entries are marginal effects of public sector. Models are OLS regression models, with standard errors shown in parentheses. All models include demographic controls (age, square term of age, gender, income, immigration status, marital status, and religion).") ///
	title("Table C.1. Marginal effects of being in the public sector") 	


*********************
* Media consumption *
*********************
* Figure 4
reg search i.tr##i.mid_inc
margins mid_inc, at(tr=(0 1))
mplotoffset, title("", ) ylabel(1(0.5)3) ///
		ytitle("Predicted value", size(medium)) xtitle("") ///
		plot1opts(bcolor("239 131 125") barw(0.2)) plot2opts(bcolor("102 197 151") barw(0.2)) ///
		ci1opt(color(black))  ci2opt(color(black)) ///
		xlabel(-0.5 " " 0 "Control group" 1 "Treatment group"   1.5 " ") ///
		legend(position(6) row(1)) recast(bar) saving(search_inc, replace) offset(0.2) scheme(538bw)
graph export "search_inc.png", as(png) replace


* recoding control variables
forvalues i=1/5{ 
	gen marital`i' =. 
	replace marital`i'=1 if marital==`i' 
	replace marital`i'=0 if marital!=`i' 
	replace marital`i'=. if marital==.
}
gen age_2=age*age

* causal mediation analysis	(Table 3)
sem (demo_imp<-search tr age age_2 gender imm marital1 marital2 marital3 marital4 reli) ///
	(search<-tr), nocaps
medsem, indep(tr) med(search) dep(demo_imp) mcreps(1000) rit rid
sem (fair<-search tr age age_2 gender imm marital1 marital2 marital3 marital4 reli)  ///
	(search<-tr), nocaps
medsem, indep(tr) med(search) dep(fair) mcreps(1000) rit rid